from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-06 14:02:25.825896
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 06, May, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1924
Nobs: 648.000 HQIC: -49.5727
Log likelihood: 7954.41 FPE: 2.32365e-22
AIC: -49.8138 Det(Omega_mle): 2.02448e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325375 0.061471 5.293 0.000
L1.Burgenland 0.105134 0.039169 2.684 0.007
L1.Kärnten -0.110296 0.020534 -5.371 0.000
L1.Niederösterreich 0.196082 0.081752 2.399 0.016
L1.Oberösterreich 0.118878 0.080739 1.472 0.141
L1.Salzburg 0.258237 0.041606 6.207 0.000
L1.Steiermark 0.043954 0.054668 0.804 0.421
L1.Tirol 0.105975 0.044111 2.402 0.016
L1.Vorarlberg -0.063514 0.038981 -1.629 0.103
L1.Wien 0.026025 0.071524 0.364 0.716
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050655 0.131384 0.386 0.700
L1.Burgenland -0.032752 0.083717 -0.391 0.696
L1.Kärnten 0.040405 0.043889 0.921 0.357
L1.Niederösterreich -0.188552 0.174731 -1.079 0.281
L1.Oberösterreich 0.447529 0.172567 2.593 0.010
L1.Salzburg 0.285436 0.088927 3.210 0.001
L1.Steiermark 0.107448 0.116844 0.920 0.358
L1.Tirol 0.313268 0.094280 3.323 0.001
L1.Vorarlberg 0.021732 0.083315 0.261 0.794
L1.Wien -0.036887 0.152870 -0.241 0.809
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189583 0.031509 6.017 0.000
L1.Burgenland 0.090364 0.020077 4.501 0.000
L1.Kärnten -0.007860 0.010526 -0.747 0.455
L1.Niederösterreich 0.248667 0.041904 5.934 0.000
L1.Oberösterreich 0.156550 0.041385 3.783 0.000
L1.Salzburg 0.040861 0.021327 1.916 0.055
L1.Steiermark 0.025426 0.028022 0.907 0.364
L1.Tirol 0.086400 0.022611 3.821 0.000
L1.Vorarlberg 0.054650 0.019981 2.735 0.006
L1.Wien 0.116805 0.036662 3.186 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112550 0.031637 3.557 0.000
L1.Burgenland 0.045473 0.020159 2.256 0.024
L1.Kärnten -0.014293 0.010569 -1.352 0.176
L1.Niederösterreich 0.180406 0.042076 4.288 0.000
L1.Oberösterreich 0.326863 0.041554 7.866 0.000
L1.Salzburg 0.101839 0.021414 4.756 0.000
L1.Steiermark 0.110474 0.028136 3.926 0.000
L1.Tirol 0.097648 0.022703 4.301 0.000
L1.Vorarlberg 0.059485 0.020063 2.965 0.003
L1.Wien -0.021178 0.036811 -0.575 0.565
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115672 0.058930 1.963 0.050
L1.Burgenland -0.043292 0.037550 -1.153 0.249
L1.Kärnten -0.046594 0.019685 -2.367 0.018
L1.Niederösterreich 0.143928 0.078372 1.836 0.066
L1.Oberösterreich 0.158399 0.077401 2.046 0.041
L1.Salzburg 0.282922 0.039886 7.093 0.000
L1.Steiermark 0.054823 0.052408 1.046 0.296
L1.Tirol 0.167333 0.042288 3.957 0.000
L1.Vorarlberg 0.096401 0.037370 2.580 0.010
L1.Wien 0.072678 0.068567 1.060 0.289
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059362 0.046450 1.278 0.201
L1.Burgenland 0.030710 0.029598 1.038 0.299
L1.Kärnten 0.051594 0.015517 3.325 0.001
L1.Niederösterreich 0.204258 0.061775 3.306 0.001
L1.Oberösterreich 0.320215 0.061010 5.249 0.000
L1.Salzburg 0.039958 0.031440 1.271 0.204
L1.Steiermark 0.007376 0.041309 0.179 0.858
L1.Tirol 0.129993 0.033332 3.900 0.000
L1.Vorarlberg 0.065181 0.029456 2.213 0.027
L1.Wien 0.092176 0.054046 1.705 0.088
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173197 0.055733 3.108 0.002
L1.Burgenland 0.005729 0.035513 0.161 0.872
L1.Kärnten -0.065252 0.018618 -3.505 0.000
L1.Niederösterreich -0.096602 0.074121 -1.303 0.192
L1.Oberösterreich 0.204728 0.073203 2.797 0.005
L1.Salzburg 0.054749 0.037723 1.451 0.147
L1.Steiermark 0.240193 0.049565 4.846 0.000
L1.Tirol 0.500928 0.039994 12.525 0.000
L1.Vorarlberg 0.059924 0.035343 1.696 0.090
L1.Wien -0.075137 0.064848 -1.159 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148449 0.061817 2.401 0.016
L1.Burgenland 0.004541 0.039389 0.115 0.908
L1.Kärnten 0.059967 0.020650 2.904 0.004
L1.Niederösterreich 0.184851 0.082212 2.248 0.025
L1.Oberösterreich -0.060244 0.081194 -0.742 0.458
L1.Salzburg 0.206989 0.041841 4.947 0.000
L1.Steiermark 0.133783 0.054976 2.433 0.015
L1.Tirol 0.070618 0.044359 1.592 0.111
L1.Vorarlberg 0.143455 0.039200 3.660 0.000
L1.Wien 0.109522 0.071926 1.523 0.128
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377909 0.036351 10.396 0.000
L1.Burgenland -0.001071 0.023163 -0.046 0.963
L1.Kärnten -0.021818 0.012143 -1.797 0.072
L1.Niederösterreich 0.210867 0.048344 4.362 0.000
L1.Oberösterreich 0.225798 0.047746 4.729 0.000
L1.Salzburg 0.038971 0.024604 1.584 0.113
L1.Steiermark -0.013974 0.032328 -0.432 0.666
L1.Tirol 0.095449 0.026086 3.659 0.000
L1.Vorarlberg 0.053277 0.023052 2.311 0.021
L1.Wien 0.036730 0.042296 0.868 0.385
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036273 0.113698 0.173010 0.141406 0.101755 0.084406 0.038205 0.210134
Kärnten 0.036273 1.000000 -0.021021 0.134279 0.052467 0.089821 0.441469 -0.060635 0.092461
Niederösterreich 0.113698 -0.021021 1.000000 0.323045 0.129672 0.284263 0.074542 0.161086 0.296272
Oberösterreich 0.173010 0.134279 0.323045 1.000000 0.221389 0.309797 0.168871 0.149323 0.249520
Salzburg 0.141406 0.052467 0.129672 0.221389 1.000000 0.130894 0.096279 0.114062 0.130071
Steiermark 0.101755 0.089821 0.284263 0.309797 0.130894 1.000000 0.138963 0.118901 0.049552
Tirol 0.084406 0.441469 0.074542 0.168871 0.096279 0.138963 1.000000 0.069186 0.148696
Vorarlberg 0.038205 -0.060635 0.161086 0.149323 0.114062 0.118901 0.069186 1.000000 0.006810
Wien 0.210134 0.092461 0.296272 0.249520 0.130071 0.049552 0.148696 0.006810 1.000000